package untiring07.mvc.actions;

import java.io.IOException;
import java.rmi.ServerException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import untiring07.mvc.dao.BoardDAO;
import untiring07.mvc.dao.MemberDAO;
import untiring07.mvc.model.BoardVO;

public class LoginAction implements ActionHandler {

	@Override
	public String execute(HttpServletRequest req, HttpServletResponse res)
			throws ServerException, IOException {
		
		String viewPage = "f|/WEB-INF/jsp/tiles/mvc.jsp";
		String method = req.getMethod();
		
		if(method.equalsIgnoreCase("get")){
			req.setAttribute("action", "../member/login.jsp");
			
		}else if(method.equalsIgnoreCase("post")){
			String uid = req.getParameter("uid");
			String pwd = req.getParameter("pwd");
			if(MemberDAO.login(uid,pwd)){
				HttpSession sess = req.getSession();/*반 영구적 데이터 보존*/
				sess.setAttribute("uid", uid);
				viewPage = "r|index.mvc";
			}else{
				req.setAttribute("action", "../member/loginfail.jsp");
			}
		}return viewPage;
	}

}
